<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>设备列表</title>
  <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  <link href="../css/mui.min.css" rel="stylesheet" />
  <!--<link rel="stylesheet" href="../css/timecheck.css" />-->
  <link rel="stylesheet" href="../fonts/iconfont.css" />
  <link rel="stylesheet" href="../css/timeChoose.css" />
  <script>
    document.documentElement.style.fontSize = document.documentElement.clientWidth / 6.4 + 'px';
  </script>
  <style>
    body{
      font-size: 0.24rem;
      margin-bottom: 0.3rem;
    }
    div,p,body,html{
      margin: 0;
      padding: 0;
      color:black;
    }
    .deviceDiv{
      width: 100%;
    }
    .title{
      width: 100%;
      text-align: center;
      background-color: white;
      padding: 1rem 0 0.05rem;
    }
    .time{
      font-size: 0.22rem;
    }
    .deviceName{
      font-size: 0.38rem;
      margin: 0.2rem 0 0.2rem;
      color:#ff6600;
    }
    .deviceInfo{
      width: 100%;
      display: flex;
      justify-content:center;
      margin-bottom: 0.2rem;
    }
    .deviceInfo p{
      width: 30%;
      font-size: 0.22rem;
    }
    .total-info{
      width: 100%;
      border-top:1px solid #ccc ;
      display: flex;
      justify-content:space-between;
      padding: 0.1rem 0.2rem;
      background-color: white;
    }
    .infoDiv{
      width: 100%;
      overflow: hidden;
      padding: 0.1rem 0.1rem 0;
      display: flex;
      justify-content:space-between;
    }
    .infoDiv>div>p{
      font-size: 16px;
    }
    .cash,.prize{
      width: 49%;
      text-align: center;
      padding: 0.1rem ;
      border-radius: 0.1rem;
      background-color: white;
    }
    .cash div,.prize div{
      width: 50%;
      float: left;
    }
    .borderRight{
      border-right: 1px solid #ccc;
    }
    .cash p,.prize p{
      margin-bottom: 0.15rem;
    }
    .storeChoose{
      width: 85%;
      margin: 0.2rem auto 0.2rem;
      border: 1px solid #ccc;
      font-size: 0.24rem;
      text-align: center;
      background-color:white ;
      overflow: hidden;
    }
    .storeChoose span{

      display: inline-block;
      width: 33%;
      padding: 0.06rem 0;
      font-size: 0.22rem;
      float: left;
    }
    .storeChoose span:nth-child(2){
      border-left: 1px solid #CCCCCC;
      border-right: 1px solid #CCCCCC;
    }
    .storeChoose span:nth-child(3){
      width: 34%;
    }
    .storeChoose .default{
      background-color: #ccc;
    }
    .bglight{
      background: white;
    }
    .gift-table{
      background: rgb(244,244,244);
    }
    .gift-table tr td div{
      width: 100%;
      padding-top: 0.1rem;
    }
    .gift-table tr td div p{
      width: 100%;
      font-size: 0.18rem;
      text-align: center;
      height: 0.2rem;
      line-height: 0.2rem;
      margin-bottom: 0.1rem;
    }
    .gift-img{
      width: 90%;
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      margin: auto;
    }
  </style>
</head>
<body>
<script src="../js/echarts.common.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/vue.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../config.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/mui.min.js"></script>
<script src="../common/timeChoose.js" type="text/javascript" charset="utf-8"></script>

<div id="app" class="mui-content deviceDiv">
  <time-choose :datetype="dateType" :todate="toDate" :fromdate="fromDate"></time-choose>

  <div class="title">
    <p class="time" v-show="dateType !== 0" >{{fromDate}} 至 {{toDate}}</p>
    <p class="time" v-show="dateType === 0" >{{toDate}}</p>
    <p class="deviceName">{{deviceName}}</p>
    <p  style="width: 100%;text-align: center">SN:{{originalData.deviceSn}}</p>
    <!--问题信息-->
    <div style="width: 100%;overflow: hidden;padding: 0.25rem 0.1rem 0;">
      <div style="float: left;">
        <img v-show="originalData.deviceState === 1&&dateType===0" src="../images/troubleflag-green.png" alt="" style="width: 0.22rem;position: relative;top:0.03rem;">
        <img v-show="(originalData.deviceState === 2||originalData.deviceState === 3||originalData.deviceState === 4)&&dateType===0" src="../images/troubleflag-red.png" alt="" style="width: 0.22rem;position: relative;top:0.03rem;">
        <img v-show="originalData.deviceState === 5&&dateType===0" src="../images/troubleflag-gray.png" alt="" style="width: 0.22rem;position: relative;top:0.03rem;">
        <img v-show="originalData.deviceState === 6&&dateType===0" src="../images/troubleflag-gray2.png" alt="" style="width: 0.22rem;position: relative;top:0.03rem;">
        <span v-show="originalData.deviceState === 1&&dateType===0" style="font-size: 0.2rem;display: inline-block;color:rgb(139,195,74) ">正常</span>
        <span v-show="originalData.deviceState === 2&&dateType===0" style="font-size: 0.2rem;display: inline-block;color:rgb(229,28,74) ">投币故障</span>
        <span v-show="originalData.deviceState === 3&&dateType===0" style="font-size: 0.2rem;display: inline-block;color:rgb(229,28,74) ">出奖故障</span>
        <span v-show="originalData.deviceState === 4&&dateType===0" style="font-size: 0.2rem;display: inline-block;color:rgb(229,28,74) ">码表故障</span>
        <span v-show="originalData.deviceState === 5&&dateType===0" style="font-size: 0.2rem;display: inline-block;color:rgb(130,130,130) ">离线</span>
        <span v-show="originalData.deviceState === 6&&dateType===0" style="font-size: 0.2rem;display: inline-block;color:rgb(205,205,205) ">未绑定</span>
      </div>
      <span style="font-size: 0.2rem;float: right;color: #9c9c9c">最后上报：{{originalData.reportDate}}</span>
    </div>
  </div>
  <div class="total-info ">
    <span>投币量: {{originalData.coins}}枚</span>
    <span v-show="deviceType ===1">总局数: {{originalData.award}}局</span>
    <!--<span v-show="type !==1">平均返奖: {{ originalData.avgAward !== null ?  originalData.avgAward : '&#45;&#45;'}}局/奖</span>-->
    <!--<span v-show="type ===1">返奖率: {{originalData.awardRate}}%</span>-->
    <span>返奖率: {{originalData.awardRate}}%</span>
  </div>
  <!--码表 start-->
  <div class="infoDiv ">
    <div class="cash ">
      <p>设备码表</p>
      <div class="borderRight">
        <p>投币计数器</p>
        <p>{{ originalData.coinsCounter}}</p>
      </div>
      <div>
        <p v-show="deviceType ===1">返奖计数器</p>
        <p v-show="deviceType !==1">出票计数器</p>
        <p>{{ originalData.awardCounter}}</p>
      </div>
    </div>
    <div class="prize">
      <p>自动抄表</p>
      <div class="borderRight">
        <p>投币计数器</p>
        <p>{{originalData.autoCoinsCounter}}</p>
      </div>
      <div>
        <p v-show="deviceType ===1">返奖计数器</p>
        <p v-show="deviceType !==1">出票计数器</p>
        <p>{{originalData.autoAwardCounter}}</p>
      </div>
    </div>
  </div>
  <div class="storeChoose">
    <span @click="choose(1)" :class="{default:type ===1 }" v-show="deviceType ===1">返奖率</span>
    <span @click="choose(2)" :class="{default:type ===2 }">投币量</span>
    <span @click="choose(3)" :class="{default:type ===3 }">机台礼品</span>
  </div>
  <!--出奖率 折线图 start-->
  <div v-show="type===1||type===2" id="prizeLine" style="width: 100%;height: 4rem; margin-top: 0.2rem;background-color: white"></div>
  <div v-show="deviceType ===1&&type===3" style="width: 100%; margin-top: 0.2rem;background-color: white">
    <div  v-show="originalData.gift===null" style="width: 100%">
      <p style="width: 100%;text-align: center;background: rgb(239,239,244);font-size: 0.2rem">无数据</p>
    </div>
    <table v-show="originalData.gift!==null" style="width: 100%" class="gift-table">
      <tr
          v-for="(item,index) in originalData.gift"
          :key="index"
          :class="{bglight:index%2===1}"
          style="width: 100%"
      >
        <td style="width: 10%;position: relative;"><img :src="item.url | fixUrl" alt=""  class="gift-img"/></td>
        <td style="width: 48%;">
          <div >
            <p style="text-align: left">{{item.name}} </p>
            <p style="text-align: left">库存单价：{{toDecimal2Percent(item.price)}}</p>
            <p style="text-align: left">上架时间：{{item.shelfTime}}</p>
          </div>
        </td>
        <!--<td style="width: 14%;">-->
          <!--<div>-->
            <!--<p>返奖单价</p>-->
            <!--<p>{{awardMoney}}</p>-->
          <!--</div>-->
        <!--</td>-->
        <td style="width: 21%;">
          <div>
            <p>机余</p>
            <p>{{item.surplus}}</p>
          </div>
        </td>
        <td style="width: 21%;">
          <div>
            <p>出奖数</p>
            <p>{{item.award}}</p>
          </div>
        </td>
      </tr>
    </table>
  </div>
  <!--投币量 折线图-->
  <!--<div id="coinLine" style="width: 100%;height: 4rem; margin-top: 0.2rem;background-color: white"></div>-->
</div>
<script type="text/javascript">
  mui.init()
  var vm = new Vue({
    el: '#app',

    data: function() {
      return {
        prizeLineOptions:{
          //标题，
          title: {
            left: 'center',
            top:5,
            textStyle: {
              fontSize: 20,
              fontWeight: 500
            }
          },
          tooltip: {
            trigger: 'axis',
            textStyle: {
              fontSize: 12
            },
            formatter: function (params) {
              var html='<p style="color:white;font-size: 12px ">'+params[0].name+'</p>'
              for(var i=0;i<params.length;i++){
                html +='<p style="color:white;font-size: 12px">' +
                  '<span style="display: inline-block;width: 10px;height:10px;border-radius:5px;margin:0 0.05rem;background-color:'+params[i].color+'"></span>' +
                  '<span >'+params[i].seriesName+'：'+params[i].data+(params[i].seriesName ==='返奖率' ? '%' :  params[i].seriesName ==='出票率' ? '张/币' : '枚') +'</span></p>'
              }
              return html
            }
          },
          legend: {
            data: ['返奖率'],
            show: true,
            bottom:10
          },
          feature: {
            dataView: {
              show: true,
              readOnly: false
            }
          },
          calculable: true,
          grid: {
            left: '2%',
            right: '5%',
            bottom: '14%',
            top: '20%',
            containLabel: true,
            borderColor: '#e2e2e2'
          },
          xAxis: [
            {
              type: 'category',
              splitLine: {
                show: false
              },
              data: [],
              axisLabel: {
                textStyle: {
                  color: '#868686',
                  fontSize: '8px'
                }
              }
            }
          ],
          yAxis: [
            {
              name:'返奖率',
              type: 'value',
              nameLocation: 'end',
              max: 100,
//              splitLine: {
//                show: false
//              },
              splitLine: {
                show:true,
                lineStyle: {
                  // 使用深浅的间隔色  
                  color: ['#b1b1b1'],
                  type:'dotted'
                }
              },
              axisLabel: {
                formatter: '{value}%',
                textStyle: {
                  color: '#868686',
                  fontSize: '8px'
                }
              }
            },
          ],
          series: [
            {
              name: '返奖率(%)',
              type: 'line',
              data:[0,30,80],
              yAxisIndex: 0,
              itemStyle: {
                normal: {
                  color: '#a3d609',        // 控制例子线条的style
                  lineStyle: {
                    color: '#a3d609'      //  lineStyle 控制对应线条style
                  },
                  label: {
                    show: false,
//                    positiong: 'top',
                    formatter: '{c}%'
                  }
                }

              },
            },

          ]
        },
        fromDate:'',
        toDate:'',
        storeName:'',
        storeId:'',
        deviceType:'',
        deviceNo:'',
        deviceId:'',
        totalData:'',
        dateType:'',
        type:1,   //1 返奖率或出票率   2 投币量
        originalData:'',
        deviceName:'',
        awardMoney:'',
      }
    },
    created:function() {
      mui.init();
      mui.plusReady(function(){
        vm.receiveParams()
      });
    },
    mounted: function() {
//      this.initCharts()
    },
    filters: {
      fixUrl: function(val) {
        if(val && val.indexOf('http://') === -1) {
          return config.imgPath + val
        }
        return val
      }
    },
    methods: {
//      获取上个页面 传的值
      receiveParams: function() {
        var sf = plus.webview.currentWebview();
        this.fromDate=sf.fromDate,
          this.toDate=sf.toDate,
          this.storeName=sf.storeName,
          this.storeId=sf.storeId,
          this.deviceType=sf.deviceType,
          this.deviceNo=sf.deviceNo,
          this.deviceId=sf.deviceId,
          this.dateType=sf.dateType,
          this.deviceName=sf.deviceName,
          this.awardMoney=sf.awardMoney
//        this.loadData();
      },
      toDecimal2Percent:function(x) {//处理充值金额，保留两位小数
        var f = parseFloat(x);
        if (isNaN(f)) {
          return false;
        }
        f = Math.round(x)/100;
        console.log("数字:"+f);
        var s = f.toString();
        var rs = s.indexOf('.');
        if (rs < 0) {
          rs = s.length;
          s += '.';
        }
        while (s.length <= rs + 2) {
          s += '0';
        }
        return s;
      },
      loadData:function() {
        var vm = this;
//        var data={
//          fromDate:new Date(vm.fromDate).format('yyyyMMdd'),
//          toDate:new Date(vm.toDate).format('yyyyMMdd'),
//          storeId:vm.storeId,
//          deviceType:1,
//          deviceNo:vm.deviceNo,
//          deviceId:vm.deviceId,
//          type:vm.dateType,
//          checkType:2,  //2  出奖
//        }
//        console.log(JSON.stringify(data))
        config.ajax({
          url:'/report/checkDevice',
          data:{
            fromDate:new Date(vm.fromDate).format('yyyyMMdd'),
            toDate:new Date(vm.toDate).format('yyyyMMdd'),
            storeId:vm.storeId,
            deviceType:1,
            deviceNo:vm.deviceNo,
            deviceId:vm.deviceId,
            type:vm.dateType,
            checkType:2,  //2  出奖
          },
          success: function(res){
            console.log(JSON.stringify(res))
            if(res.result ===1){
              vm.originalData=res.data;
              var reportStr1=new Date(vm.originalData.reportDate).format('yyyy-MM-dd hh:mm:ss');
              vm.originalData.reportDate=reportStr1;
              vm.changeChart();
            }
          },
          error:function(res){
            mui.toast(res.errormsg)
          }
        })
      },

      initCharts: function() {
        var vm = this;
        var prizeLine = echarts.init(document.getElementById('prizeLine'));
        prizeLine.setOption(vm.prizeLineOptions)
      },
      choose:function(type){
        this.type=type;
        if(this.type===1||this.type===2){
          this.changeChart();
        }
      },
      //收币和出奖切换 数据变换fun
      changeChart:function(){
        var vm=this;
        var data='',timeValue='',max=0;
        vm.prizeLineOptions.series[0].data=[],vm.prizeLineOptions.xAxis[0].data=[]
        if(vm.type ===1){
          data=JSON.parse(JSON.stringify(vm.originalData.chartAwardRate))
          vm.prizeLineOptions.yAxis[0].name= vm.deviceType === 1 ? '返奖率' : '出票率';
          vm.prizeLineOptions.yAxis[0].axisLabel.formatter= vm.deviceType === 1 ? '{value}%' : '{value}';
          vm.prizeLineOptions.series[0].name=vm.deviceType === 1 ? '返奖率' : '出票率';
          vm.prizeLineOptions.legend.data[0]=vm.deviceType === 1 ? '返奖率' : '出票率';
          vm.prizeLineOptions.series[0].itemStyle.normal.lineStyle.color='#a3d609';
          vm.prizeLineOptions.series[0].itemStyle.normal.color='#a3d609' ;
          vm.prizeLineOptions.series[0].type='line' ;
        }else{
          data=JSON.parse(JSON.stringify(vm.originalData.charCoinsCounter))
          vm.prizeLineOptions.yAxis[0].name= '投币量';
          vm.prizeLineOptions.series[0].name='投币量';
          vm.prizeLineOptions.legend.data[0]='投币量';
          vm.prizeLineOptions.yAxis[0].axisLabel.formatter=  '{value}';
          vm.prizeLineOptions.series[0].itemStyle.normal.lineStyle.color='#4472C4';
          vm.prizeLineOptions.series[0].itemStyle.normal.color='#4472C4' ;
          vm.prizeLineOptions.series[0].type='bar' ;
        }
        data.forEach(function(item,index){
          if(vm.dateType ===0){
            timeValue='近30天'
            item.day=(item.day+'').replace(/^(\d{4})(\d{2})(\d{2})$/, "$3")+'日';
          }else if(vm.dateType ===1){
            timeValue='近12周'
            item.day=item.day+'周'
          }else if(vm.dateType ===2){
            timeValue='近12个月'
            item.day=(item.day+'').replace(/^(\d{4})(\d{2})$/, "$2")+'月';
          }
          vm.prizeLineOptions.series[0].data.push(item.device);
          vm.prizeLineOptions.xAxis[0].data.push(item.day);
          if(Number(item.device) >max){
            max=Number(item.device)
          }
        });
        if(vm.type ===1){
          vm.prizeLineOptions.title.subtext=timeValue+(vm.deviceType ===1 ? '返奖率' : '出票率')
          max= parseInt(max/10)*10;
          vm.prizeLineOptions.yAxis[0].max=max > 10 ? (max+10) : 100;
        }else{
          vm.prizeLineOptions.title.subtext=timeValue+'投币量';
          max= parseInt(max/10)*10;
          vm.prizeLineOptions.yAxis[0].max=max > 10 ? (max+10) : 100;
        }
        vm.initCharts()
      }

    },
      watch: {
        fromDate: function() {
          this.loadData()
        }
      }
  })
</script>
</body>
</html>